
// pages/singer.js
import api from '../../utils/request.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Https: 'http://192.168.0.26:8081',
    currentData: 0,
    singerName: '',
    birthday: '',
    university: '',
    nationality: '',
    singerIntroduction: '',
    state: '',
    stageName: '',
    sex: '',
    singerUrl: '',
    music: [],
    album: [],
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    api.get("/singer/getSingerById", {
      id: "20",
    }).then(res => {
      // console.log(res.data);
      let datas = res.data
      this.setData({
        singerName: datas.singerName,
        birthday: datas.birthday,
        university: datas.university,
        nationality: datas.nationality,
        singerIntroduction: datas.singerIntroduction,
        state: datas.state,
        stageName: datas.stageName,
        sex: datas.sex,
        singerUrl: 'http://192.168.0.26:8081' + datas.singerUrl,
        music: datas.music,
        
      })
      // console.log(datas.music);
    }).catch(res => {
      console.log("请求错误");
    })
    api.get("/album/getAlbumBySingerId", {
      id: "20",
    }).then(res => {
      // console.log(res.data);
      let datas = res.data
      for (let i = 0; i < datas.length; i++) {
        if (datas[i].albumImg != "null" && datas[i].albumImg != '') {
          datas[i].albumImg = this.data.Https + datas[i].albumImg
        }
      }
      this.setData({
        album: datas
      })
    })
  },
  //获取当前滑块的index
  bindchange: function (e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function (e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})